import { observable, action, toJS } from 'mobx';
import * as API from '../../apis/smsReport';

export default class SmsReportStore {
  @observable reportData = {};
  @observable condition = [];
  @observable year = true;
  @observable resetOptionColor=false;
  @observable lastParams={};
  @observable init=true;
  constructor(props) {
    this.setState = this.setState.bind(this);
    this.getCondition = this.getCondition.bind(this);
    this.getReportData = this.getReportData.bind(this);
  }

  @action
  setState(params = {}) {
    Object.keys(params).forEach((v) => {
      this[v] = params[v];
    });
    return this;
  }

  @action
  getCondition(params = {}) {
    API.getCondition(params).then((data) => {
      data.api_status && (this.condition = data.config);
    });
  }

  @action
  getReportData(params = {}) {
    if (params.timeSag) {
      if (params.timeSag != 0) {
        this.lastParams = params;
      }
    } else {
      this.lastParams.timeSag = 5;
      params.timeSag = 5;
    }
    if (this.init) {
      // 第一次. 没有请求参数 默认 分部.  分部无数据. 不请求
      this.init = false;
      if (!params.orgType) params.orgType = 2;
      if (params.orgType && params.orgType == 2) {
       if (!params.subid) return;
      }
    }

    API.getReportData(params).then((data) => {
      data.api_status && (this.reportData = data.option);
    });
  }
}
